package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author zhangyu
 * @data 2023/4/24 19:40
 */
@Mapper
public interface OrderMapper {
    void addOrder(Orders orders);
    void addOrderDetail(OrderDetail orderDetail);
    @Select("select * from orders where id=#{id}")
    Orders getOrderAgain(@Param("id")Long id);
    //公共sql(分页查询订单)
    Page<Orders> getOrdersPage(OrdersPageQueryDTO ordersPageQueryDTO);
    @Select("select * from order_detail where order_id=#{id}")
    List<OrderDetail> getOrderDetailByOrderId(@Param("id")Long id);
    @Select("select * from orders where id=#{id}")
    Orders getOrderById(@Param("id")Long id);
    @Update("update orders set status=6 where id=#{id}")
    void cancelOrder(@Param("id")Long id);
    /**********************************商家端*******************************************/
    @Select("select count(*) from orders where status=#{status}")
    Integer getOrderStatus(@Param("status")Integer status);
    void update(Orders orders);
    Double moneySum(LocalDateTime start,LocalDateTime end,Integer status);
    /*************************************检查订单状态sql********************************************/
    @Select("select * from orders where status=#{status} and order_time<#{orderTime}")
    List<Orders> checkOrderStatus(@Param("status")Integer status, @Param("orderTime")LocalDateTime orderTime);
    /****************************************测试用户支付成功提醒商家来单sql********************************************************/
    @Select("select * from orders where status=2")
    List<Orders> getStatus();

    /**
     * 商家获取用户数量(public)
     * @param startEveryDay
     * @param endEveryDay
     * @return
     */
    Integer getUserCount(LocalDateTime startEveryDay,LocalDateTime endEveryDay);

    /**
     * 商家获取订单数(public)
     * @param startEveryDay
     * @param endEveryDay
     * @return
     */
    Integer getOrderCount(LocalDateTime startEveryDay,LocalDateTime endEveryDay,Integer status);

    /**
     * 商家指定时间获取商品销售top10
     * @param start
     * @param end
     * @return
     */
    List<GoodsSalesDTO> getTop10List(LocalDateTime start,LocalDateTime end);
}
